package jp.ac.waseda.cs.washi.game.entity;

import jp.ac.waseda.cs.washi.game.api.GameTimerInfo;

public class GameTimer {
	class GameTimerInfoImpl implements GameTimerInfo {
		@Override
		public int getRemainingTime() {
			return GameTimer.this.getRemainingTime();
		}

		@Override
		public int getTime() {
			return GameTimer.this.getTime().getCurrentTime();
		}

		@Override
		public boolean isOver() {
			return GameTimer.this.isOver();
		}
	}

	private GameTimerInfo _info;
	private GameTime _time;
	private int _endTime;

	public GameTimer(GameTime time, int span) {
		_time = time;
		_endTime = time.getCurrentTime() + span;
		_info = new GameTimerInfoImpl();
	}

	public GameTime getTime() {
		return _time;
	}

	public boolean isOver() {
		return _time.getCurrentTime() >= _endTime;
	}

	public int getRemainingTime() {
		return isOver() ? 0 : _endTime - _time.getCurrentTime();
	}

	public GameTimerInfo getInfo() {
		return _info;
	}
}
